#ifndef MODBUSMANAGE_H
#define MODBUSMANAGE_H

#include <QObject>
#include "ModbusClient.h"

class ModbusManage : public QObject
{
    Q_OBJECT
public:

    ModbusManage();

    void ModbusInit();

    ModbusAll getModbusAllData();

    void MoubusReadCoil_QR(int address, int number);// 读取指定Modbus线圈指定值

    void MoubusReadCoil_QC(int address, int number);// 读取指定Modbus线圈指定值

    void MoubusReadCoil_RS(int address, int number);// 读取指定Modbus线圈指定值

    void MoubusReadCoil_RX(int address, int number);// 读取指定Modbus线圈指定值

signals:

    void sig_AllModbusData(ModbusAll _ModbusAll);// 获取所有 Modbus 数据

public slots:

    void ON_MoubusWriteCoil_QR(int address, quint16 value);// 指定Modbus线圈写入指定值

    void ON_MoubusWriteCoil_QC(int address, quint16 value);// 指定Modbus线圈写入指定值

    void ON_MoubusWriteCoil_RS(int address, quint16 value);// 指定Modbus线圈写入指定值

    void ON_MoubusWriteCoil_RX(int address, quint16 value);// 指定Modbus线圈写入指定值

    void ON_MoubusWriteCoil_Client(int address, quint16 value);// 指定Modbus线圈写入指定值

private slots:

    void ModbusManageTimer_Read_QR();

    void ModbusManageTimer_Read_QC();

    void ModbusManageTimer_Read_RS();

    void ModbusManageTimer_Read_RX();

private:

    QTimer *Timer_Read_QR;
    QTimer *Timer_Read_QC;
    QTimer *Timer_Read_RS;
    QTimer *Timer_Read_RX;

    ModbusAll _AllModbusData;

    ModbusClient *_Client_QR;                           // modbus Client 读对象
    ModbusClient *_Client_QC;                           // modbus Client 读对象
    ModbusClient *_Client_RS;                           // modbus Client 读对象
    ModbusClient *_Client_RX;                           // modbus Client 读对象

    ModbusClient *_QR_Write;                            // modbus Client 写对象
    ModbusClient *_QC_Write;                            // modbus Client 写对象
    ModbusClient *_RS_Write;                            // modbus Client 写对象
    ModbusClient *_RX_Write;                            // modbus Client 写对象

    ModbusClient *_Client_Write;                        // modbus Client 写对象

//    QString _Client_ip="127.0.0.1";                     // mudbus Server IP
    QString _Client_ip="192.168.1.100";                 // mudbus Server IP

    int _Port=5502;                                     // mudbus Server Port

    int _last_QR=-1;                                    // 心跳记录
    int _last_QC=-1;                                    // 心跳记录
    int _last_RS=-1;                                    // 心跳记录
    int _last_RX=-1;                                    // 心跳记录

};

#endif // MODBUSMANAGE_H
